


//window.onload 当网页加载完事执行
window.onload = function(){
	
	//此时才能调用加载的js
	
}

//放到外面先执行
//执行顺序问题
	
var flag = true;//加载条件
	
	
	if(flag){
	loadScript("../js/22DOM.js");
	loadCss("../css/22DOM01.css");
	loadStyle();
	
	}
	//拼接脚本文件文件
 function loadScript(url){
		var script = document.createElement("script");
		script.type = "text/jscript";
		script.src =url
		//也可以拼接代码
		//script.text="alert('123')";		
		document.getElementsByTagName('head')[0].appendChild(script);
		
}


//动态加载css

function loadCss(href){
	var  link = document.createElement("link");
	link.rel ='stylesheet';
	link.type='text/css';
	link.href=href;
	document.getElementsByTagName('head')[0].appendChild(link)
}

//动态加载style

function loadStyle(){
	var style = document.createElement('style');
	style.type='text/css';
	document.getElementsByTagName('head')[0].appendChild(style);
	insertRule(document.styleSheets[0],"#box","width:300px;height:200px;background:blue;",0);
}

//兼容ie
function insertRule(sheet,selectorText,cssText,position){
	//如果是非ie
	if (sheet.insertRule) {
		sheet.insertRule(selectorText+"{"+cssText+"}",position);
	//如果非ie
	} else if(sheet.addRule){
		sheet.addRule(selectorText,cssText,position);
	}
}
